Repository navigation
Conversation
| try { | ||
| return `The median is ${calculateMedian(list)}`; | ||
| } catch (error) { | ||
| return `Could not calculate a median: calculateMedian requires a non-empty array: ${error.message}`; |
There was a problem hiding this comment.
What exact sentence does this return when calculateMedian throws the empty-array error, compared with the example in the acceptance criteria?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
"Could not calculate a median: calculateMedian requires a non-empty array"
| expect(() => sum([null])).toThrow( | ||
| new Error("sum requires an array of numbers") | ||
| ); | ||
| expect(() => sum([3])).toThrow(new Error("sum requires an array of numbers")); |
There was a problem hiding this comment.
These assertions expect sum([3]) to throw, so the suite fails for a valid array of numbers. The purported non-array test repeats array inputs instead of checking a non-array.
To "like" or "dislike" this comment, please follow this link
| } | ||
| total = total + item; | ||
| } | ||
| return Number(total.toFixed(2)) / list.length; |
There was a problem hiding this comment.
What happens to the mean of values with more than two decimal places when the total is rounded before dividing?
To "like" or "dislike" this comment, please follow this link
| test("given [1, 2, 3], returns The median is 2", () => { | ||
| const list = [1, 2, 3]; | ||
| const result = describeMedian(list); | ||
| expect(describeMedian(list)).toEqual(result); |
There was a problem hiding this comment.
What incorrect sentence would either of these assertions catch if describeMedian returned the wrong result?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
"Could not calculate a median: calculateMedian requires a non-empty array"
| const list = []; | ||
| const result = describeMedian(list); |
There was a problem hiding this comment.
Does this test pass a non-array value to describeMedian?
To "like" or "dislike" this comment, please follow this link
| // When passed to calculateMean | ||
| // Then it should return that number | ||
| test("given [6], returns 6", () => { | ||
| expect(6).toEqual(6); |
There was a problem hiding this comment.
What function call is this assertion checking?
To "like" or "dislike" this comment, please follow this link
| test("given an empty array, it returns an empty array", () => { | ||
| const list = []; | ||
| const result = dedupe(list); | ||
| expect(dedupe(list)).toEqual(result); |
There was a problem hiding this comment.
What output does this test require for an empty list?
To "like" or "dislike" this comment, please follow this link
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| if (!elements.length === 1) { |
There was a problem hiding this comment.
For a one-element array, what does !elements.length compare with 1?
To "like" or "dislike" this comment, please follow this link
|
The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look. |
cjyuan
left a comment
There was a problem hiding this comment.
Could you also addressed the comments by AI?
| // Don't change this function. | ||
| function calculateMedian(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("calculateMedian requires an array of numbers"); | ||
| throw new Error( | ||
| "Could not calculate a median: calculateMedian requires a non-empty array" | ||
| ); |
There was a problem hiding this comment.
You were not supposed to change this function (per instruction on line 1).
What you should do is find a way to reuse the error message in describeMedian() when it catches the error thrown by calculateMedian().
Your previous approach was in the right direction except that it didn't return the expected string.
Learners, PR Template
Self checklist
Task code
CYF-1071
Changelist
Fix, refactor and implement code. Write test cases for the program.